<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/6/28
 * Time: 上午9:53
 */

namespace app\mall\controller;


use think\Request;

class Cart extends Auth
{
    /**
     * @purpose 获取购物车商品数量
     * @return array
     */
    public function total ()
    {
        return \app\mall\logic\Cart::total(self::$uid);
    }
    /**
     * @purpose 获取购物车商品信息
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function item () {
        return \app\mall\logic\Cart::item(self::$uid);
    }
    /**
     * @purpose 添加商品到购物车
     * @param Request $request
     * @return array
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function add (Request $request)
    {
        $goods_id       = $request->post('goods_id');
        $goods_number   = $request->post('goods_number', '');
        $number         = $request->post('number');
        return  \app\mall\logic\Cart::add($goods_id,$goods_number,$number,self::$uid);
    }

    /**
     * @purpose 删除购物车选中的商品
     * @param Request $request
     * @return array
     * @throws \Exception
     */
    public function del (Request $request)
    {
        $ids    =   $request->post();
        return \app\mall\logic\Cart::del($ids, self::$uid);
    }

    /**
     * @purpose 修改购物车商品购买数量
     * @param Request $request
     * @return array
     */
    public function changeNumber (Request $request)
    {
        $number     = $request->post('number');
        $id         = $request->post('id');
        return \app\mall\logic\Cart::changeNumber($id, $number, self::$uid);
    }
}